using System.Net.Sockets;
using System.Net;

namespace Fusion.Net
{
    public class NetUtility
    {
        public static IPAddress GetIP(AddressFamily addressFamily)
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
            int length = hostEntry.AddressList.Length;
            for (int i = 0; i < length; i++)
            {
                IPAddress address = hostEntry.AddressList[i];
                if (address.AddressFamily == addressFamily)
                {
                    return address;
                }
            }
            return null;
        }

        public static IPAddress GetIP()
        {
            IPAddress ip = GetIP(AddressFamily.InterNetworkV6);
            return ip ?? GetIP(AddressFamily.InterNetwork);
        }

        public static bool OSSupportsIPv6()
        {
            return GetIP(AddressFamily.InterNetworkV6) != null;
        }

        public static bool OSSupportsIPv4()
        {
            return GetIP(AddressFamily.InterNetwork) != null;
        }
    }
}


